#ifndef GNSS_PARSER_H
#define GNSS_PARSER_H

#include "common.h"
#include "vector3d.h"

#define MAX_SATELLITES 32
#define GNSS_BUFFER_SIZE 1024

// GNSS卫星数据结构
typedef struct {
    int prn;                // 卫星编号
    Vector3D position;      // 卫星位置 (ECEF坐标系)
    Vector3D velocity;      // 卫星速度
    double clock_bias;       // 时钟偏差
    double signal_strength;  // 信号强度
    double pseudorange;      // 伪距
    double doppler_shift;    // 多普勒频移
} GNSS_Satellite;

// GNSS接收机数据结构
typedef struct {
    Vector3D position;      // 接收机位置 (ECEF坐标系)
    Vector3D velocity;      // 接收机速度
    double clock_bias;       // 接收机时钟偏差
    double clock_drift;      // 接收机时钟漂移
    int visible_satellites;  // 可见卫星数量
    double pdop;             // 位置精度因子
    double hdop;             // 水平精度因子
    double vdop;             // 垂直精度因子
} GNSS_Receiver;

// GNSS原始数据
typedef struct {
    char buffer[GNSS_BUFFER_SIZE];
    size_t length;
    double timestamp;
} GNSS_RawData;

// 函数声明
ErrorCode gnss_parse_nmea(const char* nmea_sentence, GNSS_Satellite* satellites, int* count);
ErrorCode gnss_calculate_position(GNSS_Satellite* satellites, int count, GNSS_Receiver* receiver);
ErrorCode gnss_simulate_data(GNSS_Satellite* satellites, int* count, GNSS_Receiver* receiver);
Vector3D gnss_ecef_to_geodetic(Vector3D ecef);
Vector3D gnss_geodetic_to_ecef(Vector3D geodetic);

// 工具函数
double gnss_calculate_distance(Vector3D a, Vector3D b);
double gnss_calculate_pseudorange(Vector3D receiver, Vector3D satellite, double clock_bias);
void gnss_print_receiver(const GNSS_Receiver* receiver);

#endif // GNSS_PARSER_H
